package com.qdsg.ysg.doctor.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.rest.response.PrescriptionResponse;

import java.util.List;

import androidx.recyclerview.widget.RecyclerView;

import com.qdsg.ysg.doctor.R;

import org.jetbrains.annotations.NotNull;

/**
 * @time 2020/12/1 17:56
 */

public class MedicineAdapter extends RecyclerView.Adapter<MedicineAdapter.Holder> {

    private Context context;
    private List<PrescriptionResponse.Prescription> list;

    public MedicineAdapter(Context context, List<PrescriptionResponse.Prescription> list) {
        this.context = context;
        this.list = list;
    }


    @NotNull
    @Override
    public MedicineAdapter.Holder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {
        MedicineAdapter.Holder myHolder;
        myHolder = new Holder( LayoutInflater.from( context ).inflate( R.layout.item_medicine, parent, false ) );
        return myHolder;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(MedicineAdapter.Holder holder, final int position) {
        holder.itemView.setOnClickListener( v -> {
//                Bundle bundle = new Bundle();
//                bundle.putSerializable("obj", list.get(position));
//                startActivity(CheckActivity.class, bundle);
        } );
        PrescriptionResponse.Prescription prescription = list.get( position );
        holder.tv_medicine_name.setText( prescription.name );
        holder.tv_medicine_base_num.setText( prescription.drugFrequency + "  " + prescription.drugDose  + "  " + prescription.drugChannel );
//        holder.tv_medicine_base_num.setText( prescription.drugFrequency + "  " + prescription.drugDose + prescription.specialUnit + "/次" + "  " + prescription.drugChannel );
        holder.tv_medicine_num.setText( list.get( position ).drugNumber );
        holder.tv_medicine_price.setText( list.get( position ).expense );
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class Holder extends RecyclerView.ViewHolder {

        TextView tv_medicine_name, tv_medicine_num, tv_medicine_base_num, tv_medicine_price;

        Holder(View itemView) {
            super( itemView );
            tv_medicine_name = itemView.findViewById( R.id.tv_medicine_name );
            tv_medicine_num = itemView.findViewById( R.id.tv_medicine_num );
            tv_medicine_base_num = itemView.findViewById( R.id.tv_medicine_base_num );//计量
            tv_medicine_price = itemView.findViewById( R.id.tv_medicine_price );
        }
    }
}
